<?php get_header();?>
<?php get_sidebar('dxn');?>
    <div id="homeWrapper" class="clearfix">
<?php 

$lang = $_GET['lang'];

////////////////////////////
$slug = $_GET['the-loai-phim'];
//get_term_by('slug',$value,$taxonomy) //can change 'slug' to 'id' or 'name'
$cat_title = get_term_by('slug',$slug,'the-loai-phim');	//print_r($cat_title);die;
$newargs = array( 'post_type'=>'danh-sach-phim',
						'tax_query'=>array(
											array(
												'taxonomy'=>'the-loai-phim',
												'field'=>'slug',
												'terms'=>$slug
												)
											)
						);
						
	?>
    <div class="box-fim" style="float:left; width:600px;">
     <h2 style="margin-bottom:20px; "><a style="color:#ffffff; background-color:#C03; padding:4px 20px; margin:10px 0px; float:left; width:600px" href="#" class="tit-link"><?php echo $cat_title->name;?></a></h2>
    <?php
	query_posts($newargs); 
	if(have_posts()) : while(have_posts()) : the_post();	?>
	
		<div <?php post_class($p3);?> id="product-<?php the_ID();?>" style="float:left; padding:10px; margin-bottom:10px"> 
          <?php the_post_thumbnail(array('class'=>'image-1'));  ?>
                <a href="<?php the_permalink();?>"><h3 class="product-title"><?php the_title();?></h3></a>
                <div class="info">
                        <p style="margin-top:5px;"><?php echo get_post_meta($post->ID,'wpcf-phone',true);?></p>
                        <p class="product-status">
                            <?php 
                            $product_status = get_post_meta($post->ID,'wpcf-product-status',true);
							if($product_status == 1)
                            	echo '<strong style="color:green;">Đang chiếu</strong>';
							else
								echo '<strong style="color:green;">Sắp chiếu</strong>';
                            ?>
                        </p>
                        <a class="order-button" href="<?php the_permalink();?>">Xem chi tiết</a>
                        </div> 
       </div>
	<?php	
	endwhile;		//die;					
	endif;
	echo'</div>';

//////////////////////////////////
?>

    </div><!--end #homeWrapper-->
 <!--Add dropdown menu categories--->   
<?php
  $cates = get_categories('taxonomy=the-loai-phim&parent=0'); //print_r($cates);die;
  $select = "<select name='cat' id='cat' class='postform'>n";
  $select .= "<option value='-1'>Select category</option>n";

  foreach($cates as $cate){
	  $parent = $cate->term_id;
    if($cate->count > 0){
        $select.= "<option value='".$cate->slug."'>".$cate->name."</option>";
		$subcates = get_categories(array('taxonomy'=>'the-loai-phim',
										'hide_empty'=>0,
										'parent'=>$parent
										)
									);
		if(count($subcates)>0){
			foreach($subcates as $subcate){
				$select .= "<option value='".$subcate->slug."'>|--".$subcate->name."</option>";	
			}
		}
    }
  }
  
  $select.= "</select>";
  
  echo $select;
?>
  
<script type="text/javascript">
    var dropdown = document.getElementById("cat");
    function onCatChange() {
        if ( dropdown.options[dropdown.selectedIndex].value != -1 ) {
            location.href = "<?php echo site_url();?>/?the-loai-phim="+dropdown.options[dropdown.selectedIndex].value+"&lang=<?=$lang?>";
        }
    }
    dropdown.onchange = onCatChange;
</script>
<!--End add dropdown menu categories---->   
<?php get_footer(); ?>